package com.ssyt.yt1.day8;

import java.util.Arrays;

/**
 * 回调：传一段自己定义的逻辑给目标方法（控制权交给调用者）！
 * 
 * @author Administrator
 *
 */

abstract class Sort {

	public abstract void sort();
}

class JDKSort extends Sort {

	private int[] numbers;

	public JDKSort() {

	}

	public JDKSort(int[] numbers) {
		this.numbers = numbers;
	}

	@Override
	public void sort() {
		Arrays.sort(numbers);
		System.out.println(Arrays.toString(numbers));
	}
}

class BubbleSort extends Sort {

	private int[] numbers;

	public BubbleSort() {

	}

	public BubbleSort(int[] numbers) {
		this.numbers = numbers;
	}

	@Override
	public void sort() {
		for (int i = 0; i < numbers.length - 1; i++) {
			for (int j = 0; j < numbers.length - i - 1; j++) {
				if (numbers[j] > numbers[j + 1]) {
					int temp = numbers[j];
					numbers[j] = numbers[j + 1];
					numbers[j + 1] = temp;
				}
			}
		}
		System.out.println(Arrays.toString(numbers));
	}
}

class Array {

	public void sort(Sort sort) {
		sort.sort();
	}
}

public class Callback {

	public static void main(String[] args) {
		Array array = new Array();
		array.sort(new JDKSort(new int[] { 12, 23, 3, 242, 3134, 12, 3412 }));
	}
}
